﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MySoftLab.DapFlashCore.Targets
{
    public class FlashAlgo
    {
        public uint LoadAddress { get; set; }

        public uint[] Instructions { get; set; } = new uint[0];

        public uint PcInit { get; set; }

        public uint PcUnInit { get; set; }

        public uint PcProgramPage { get; set; }

        public uint PcEraseSector { get; set; }

        public uint PcEraseAll { get; set; }

        public uint StaticBase { get; set; }

        public uint BeginStack { get; set; }

        public uint EndStack { get; set; }

        public uint BeginData { get; set; }

        public uint PageSize { get; set; }

        public uint SectorSize { get; set; }

        public uint[] PageBuffers { get; set; } = new uint[0];

        public uint MinProgramLength { get; set; } = 8;

        public bool AnalyzerSupported { get; set; }

        public uint AnalyzerAddress { get; set; }

        public Dictionary<string, string> Properties { get; set; } = new Dictionary<string, string>();

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append($"LoadAddress:0x{LoadAddress:X8}\n");
            sb.Append($"PcInit:0x{PcInit:X8}\n");
            sb.Append($"PcUnInit:0x{PcUnInit:X8}\n");
            sb.Append($"PcProgramPage:0x{PcProgramPage:X8}\n");
            sb.Append($"PcEraseSector:0x{PcEraseSector:X8}\n");
            sb.Append($"PcEraseAll:0x{PcEraseAll:X8}\n");
            sb.Append($"StaticBase:0x{StaticBase:X8}\n");
            sb.Append($"BeginStack:0x{BeginStack:X8}\n");
            sb.Append($"EndStack:0x{EndStack:X8}\n");
            sb.Append($"BeginData:0x{BeginData:X8}\n");
            sb.Append($"PageSize:0x{PageSize:X8}\n");
            sb.Append($"SectorSize:0x{SectorSize:X8}\n");
            sb.Append($"PageBuffers:0x{PageBuffers[0]:X8}\n");
            sb.Append($"MinProgramLength:{MinProgramLength}\n");

            return sb.ToString();
        }
    }
}
